﻿using System.Linq;
using Moq;
using Myotragus.Data.Emit;
using Myotragus.Data.Tests.Domain;
using Myotragus.Data.Tests.Utils;
using Myotragus.Data.Util;
using NUnit.Framework;

namespace Myotragus.Data.Tests.Tests.Emit
{
	[TestFixture]
	public class AutoPropertyFixture
	{
		[Test]
		public void CreateAnEntity()
		{
			var typ = new Mock<IDynamicType>();
			var asm = FixturesHelper.CreateAssemblyMock("Mocked.DynamicAssembly", typ);
			var automaticProperty = new AutoPropertiesEntityGenerator(asm, 
				FixturesHelper.CreateNameGenerator());

			automaticProperty.GetImplementation(typeof(ITestEntity2));

			foreach (var property in typeof(ITestEntity).GetProperties())
				typ.Verify(m => m.DefineAutomaticProperty(property.Name, property.PropertyType),
					Times.Exactly(1));
			foreach (var property in typeof(ITestEntity2).GetProperties())
				typ.Verify(m => m.DefineAutomaticProperty(property.Name, property.PropertyType),
					Times.Exactly(1));
			foreach (var property in ReflectionHelper.GetProperties(typeof(ITestEntity2)))
				typ.Verify(m => m.DefineAutomaticProperty(property.Name, property.PropertyType),
					Times.Exactly(1));
		}
	}
}